﻿@model PagedList.IPagedList<TaoNiuOA.Models.Apply>
@using PagedList;
@{    
    ViewBag.Title = "申请审批管理";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
    var ac = new TaoNiuOA.Web.Controllers.ApplyController();
}
<script type="text/javascript">
    function showStatus(obj) {
        switch (obj) {
            case 0:
                document.write("拒绝");
                break;
            case 1:
                document.write("同意");
                break;
            default:
                document.write("审批中");
                break;
        }
    }
</script>
<fieldset>
    <legend>申请审批管理 | <a href="../ApplyType/index">审批类型管理</a></legend>
    <div>
        <ul>
            <li><a href="?mod=all">所有申请(@ViewData["allcount"])</a></li>
            <li><a href="?mod=agree">已同意的(@ViewData["agreecount"])</a></li>
            <li><a href="?mod=approve">审批中的(@ViewData["approvecount"])</a></li>
            <li><a href="?mod=refuse">已拒绝的(@ViewData["refusecount"])</a></li>
        </ul>
    </div>
    <table>
        <tr>
            <th>
                申请人
            </th>
            <th>
                标题
            </th>
            <th>
                申请时间
            </th>
            <th>
                类型
            </th>
            <th>
                开始时间
            </th>
            <th>
                结束时间
            </th>
            <th>
                状态
            </th>
            <th>
                审批者
            </th>
            <th>
                操作
            </th>
        </tr>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @item.GetUser().GetUserInfo().Name
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Title)
                </td>
                <td>
                    @item.ApplyTime
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.GetApplyType().TypeName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.StartTime)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.EndTime)
                </td>
                <td>
                    <script>showStatus(@item.Status);</script>
                </td>
                <td>
                    @item.GetApprover().GetUserInfo().Name
                </td>
                <td>
                    @Html.ActionLink("详细", "Details", new { id = item.ApplyID })
                    | <a href="javascript:void(0);" onclick="popshow(@item.ApplyID);">审批</a>
                </td>
            </tr>
        }
    </table>
    <div style="width: auto; height: 30px; margin-top: 20px; text-align: center;">
        @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
        / @Model.PageCount
        &nbsp;
        @if (Model.HasPreviousPage)
        {
            @Html.ActionLink("首页", "Index", new { mod = ViewData["mod"], page = 1, currentFilter = ViewBag.CurrentFilter })
            @Html.Raw("&nbsp;");
            @Html.ActionLink("上一页", "Index", new { mod = ViewData["mod"], page = Model.PageNumber - 1, currentFilter = ViewBag.CurrentFilter })
        }
        else
        {
            @:首页
        @Html.Raw("&nbsp;");
            @:上一页
                         }
        &nbsp;
        @if (Model.HasNextPage)
        {
            @Html.ActionLink("下一页 ", "Index", new { mod = ViewData["mod"], page = Model.PageNumber + 1, currentFilter = ViewBag.CurrentFilter })
            @Html.Raw("&nbsp;");
            @Html.ActionLink("尾页", "Index", new { mod = ViewData["mod"], page = Model.PageCount, currentFilter = ViewBag.CurrentFilter })
        }
        else
        {
            @:下一页
        @Html.Raw("&nbsp;")
            @:尾页
                       }
    </div>
</fieldset>
<link href="../../Plusins/jQtip/jqTip.css" rel="stylesheet" type="text/css" />
<div>
    <div id="popupText">
        <h1>
            审批
        </h1>
        <div id="textArea">
            <form id="popupForm" action="" method="post">
            <div id="popupMain" style="text-align: center;">
                <select id="agree" name="agree">
                    <option value="1" selected="selected">同意</option>
                    <option value="0">拒绝</option>
                </select>
                <input type="hidden" id="ApplyID" name="ApplyID" value="" />
            </div>
            <br />
            <br />
            <div style="text-align: center;">
                <input type="button" value="确定" id="popSubmit" />
                <input type="button" value="取消" id="popCancel" />
            </div>
            </form>
        </div>
    </div>
    <div id="backgroundPopup">
    </div>
</div>
<script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
    //打开弹出窗口
    //按钮点击事件
    function popshow(obj) {
        //设置弹出层的大小
        $("#popupText").css({ height: "180", width: "250" });
        document.getElementById("ApplyID").value = obj;
        //调用函数居中窗口
        centerPopup();
        //调用函数加载窗口
        loadPopup();
    }

    //初始化：是否开启DIV弹出窗口功能
    //0 表示开启; 1 表示不开启;
    var popupStatus = 0;
    //使用Jquery加载弹窗 
    function loadPopup() {
        //仅在开启标志popupStatus为0的情况下加载  
        if (popupStatus == 0) {
            $("#backgroundPopup").css({
                "opacity": "0.7"
            });
            $("#backgroundPopup").fadeIn("slow");
            $("#popupText").fadeIn("slow");
            popupStatus = 1;
        }
    }
    //使用Jquery去除弹窗效果 
    function disablePopup() {
        //仅在开启标志popupStatus为1的情况下去除
        if (popupStatus == 1) {
            $("#backgroundPopup").fadeOut("slow");
            $("#popupText").fadeOut("slow");
            popupStatus = 0;
        }
    }
    //将弹出窗口定位在屏幕的中央
    function centerPopup() {
        //获取系统变量
        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;
        var popupHeight = $("#popupText").height();
        var popupWidth = $("#popupText").width();
        //居中设置   
        $("#popupText").css({
            "position": "absolute",
            "top": windowHeight / 2 - popupHeight / 2,
            "left": windowWidth / 2 - popupWidth / 2
        });

        //以下代码仅在IE6下有效
        $("#backgroundPopup").css({
            "height": windowHeight
        });
    }
    //确定
    $("#popSubmit").click(function () {
        var appid = $("#ApplyID").val();
        var status = $("#agree").val();
        $.post("agree?id=" + appid + "&status=" + status, function (data) {
            alert(data);
            disablePopup();
            if (data == "审批成功") {
                window.location.reload();
            }
        });
    });


    //取消
    $("#popCancel").click(function () {
        disablePopup();
    });
</script>
